<template>
  <div id="cmt">
    <div style="margin:10px 10% 0px 10%">
      <section>
        <b-field label="评论">
          <b-input maxlength="200" type="textarea" v-model="text"></b-input>
        </b-field>
      </section>
      <b-button type="is-dark" @click="uploadComment()">发表</b-button>
    </div>

    <div
      style="margin:10px 10% 0 10%"
      v-for="i in comment"
      :key="i.id"
      @click="comein(i.commentId)"
    >
      <b-message
        v-bind:title="i.userName"
        type="is-info"
        aria-close-label="Close message"
        v-model="i.userName"
      >
        {{ i.commentMsg }}
      </b-message>
    </div>
  </div>
</template>

<script>
export default {
  name: "Comment",
  data() {
    return {
      id:"",
      pointId:"",
      comment: [],
      text: "",
    };
  },
  methods: {
    async comein(title1) {
      // console.log(title);
      this.$router.push({
        path: "/post",
        query: {
          title: title1,
        },
      });
    },
    async uploadComment() {
      console.log(this.text)
      console.log(typeof(this.id))
      console.log(this.pointId)
      let res = await this.$http.post("api/2backcode/comment/add"+"?commentMsg="+this.text+"&id="+this.id+"&pointId="+this.pointId);
      console.log(res.data);
      this.$router.go(0)
    },
    async getAllComment() {
      let res = await this.$http.get("api/2backcode/comment/find",{
        params:{
          pointId:this.pointId
        }
      });
      this.comment = res.data;
      console.log(res.data);
    },
  },
  async mounted() {
    this.pointId=await this.$route.query.value
    // console.log(this.pointId)
    // this.pointId=await localStorage.getItem("id")
    this.id=await localStorage.getItem("email")
    // console.log(this.pointId)
    // console.log(this.id)
    //dldldldl
    this.getAllComment();
  },
};
</script>

<style>
#cmt {
}
</style>
